package com.chenglu.android.payment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chenglu.android.R;
import com.chenglu.android.common.base.BaseFullScreenActivity;
import com.chenglu.android.common.base.Global;
import com.chenglu.android.common.net.Constant;
import com.chenglu.android.common.utils.BaseDialog;
import com.chenglu.android.common.utils.BigDecimalUtil;
import com.chenglu.android.common.utils.LogUtils;
import com.chenglu.android.common.utils.SPUtils;
import com.chenglu.android.common.utils.StatusBarUtil;
import com.chenglu.android.common.utils.ToastUtils;
import com.chenglu.android.common.utils.Utils;
import com.chenglu.android.mine.address.AddressManagerActivity;
import com.chenglu.android.mine.bean.AddressListBean;
import com.chenglu.android.payment.adapter.ComfirmOrderAdapter;
import com.chenglu.android.payment.adapter.DayListAdapter;
import com.chenglu.android.payment.adapter.DayTimeListAdapter;
import com.chenglu.android.payment.adapter.OrderCouponAdapter;
import com.chenglu.android.payment.adapter.OrderPaytypeAdapter;
import com.chenglu.android.payment.bean.Address;
import com.chenglu.android.payment.bean.ComfirmOrderBean;
import com.chenglu.android.payment.bean.CouponListBean;
import com.chenglu.android.payment.bean.OrderGoodsList;
import com.chenglu.android.payment.bean.PayOrderBean;
import com.chenglu.android.payment.bean.PayTypeConfig;
import com.chenglu.android.payment.bean.PostDayBean;
import com.chenglu.android.payment.bean.PostTimeListBean;
import com.chenglu.android.payment.bean.TenantIdPayMethod;
import com.chenglu.android.payment.mvp.contract.ComfirmOrderContract;
import com.chenglu.android.payment.mvp.presenter.ComfirmOrderPresenter;
import com.chenglu.android.payment.pay.PayStatusActivity;
import com.google.gson.Gson;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.animator.PopupAnimator;
import com.lxj.xpopup.core.BottomPopupView;
import com.lxj.xpopup.interfaces.OnConfirmListener;
import com.lxj.xpopup.interfaces.OnInputConfirmListener;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author: lyj
 * @Created: by Copyright 2023 3 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：预确认订单界面
 */
public class ComfirmOrderActivity extends BaseFullScreenActivity<ComfirmOrderPresenter> implements ComfirmOrderContract.View {


    public static final String MOBILE = "mobile";
    public static final String ORDERTYPE = "orderType";
    public static final String REALNAME = "realName";
    public static final String PAYTYPE = "payType";
    public static final String LAT = "lat";
    public static final String LNG = "lng";
    public static final String TENANTID = "tenantId";
    public static final String POSTTYPE = "postType";
    public static final String SHOPSTYPEID = "shopsTypeId";


    //商超 商品集合
    public static final String ORDERGOODSLIST = "OrderGoodsList";
    //餐饮
    public static final String ORDERRESTAURANTEXLIST = "OrderRestaurantExList";

    public static final String ADDRESSID = "addressId";


    @BindView(R.id.iv_header)
    FrameLayout ivHeader;
    @BindView(R.id.iv_order)
    ImageView ivOrder;
    @BindView(R.id.tv_order_name)
    TextView tvOrderName;
    @BindView(R.id.tv_order_phone)
    TextView tvOrderPhone;
    @BindView(R.id.tv_order_address)
    TextView tvOrderAddress;
    @BindView(R.id.tv_check_address)
    TextView tvCheckAddress;
    @BindView(R.id.tv_no_address)
    TextView tvNoAddress;
    @BindView(R.id.iv_right)
    ImageView ivRight;
    @BindView(R.id.rl_order_address)
    RelativeLayout rlOrderAddress;
    @BindView(R.id.iv_cart_seller)
    ImageView ivCartSeller;
    @BindView(R.id.tv_cart_sellername)
    TextView tvCartSellername;
    @BindView(R.id.rv_cart_item)
    RecyclerView rvCartItem;
    @BindView(R.id.tv_order_price)
    TextView tvOrderPrice;
    @BindView(R.id.tv_order_yunfei)
    TextView tvOrderYunfei;
    @BindView(R.id.tv_view_startup)
    TextView tvViewStartup;
    @BindView(R.id.rl_startup_value)
    RelativeLayout rlStartupValue;
    @BindView(R.id.tv_order_youhui)
    TextView tvOrderYouhui;
    @BindView(R.id.tv_order_cart_sum)
    TextView tvOrderCartSum;
    @BindView(R.id.tv_peisong_mothed)
    TextView tvPeisongMothed;
    @BindView(R.id.tv_order_remarks_edit)
    TextView tvOrderRemarksEdit;

    @BindView(R.id.tv_order_coupon)
    TextView tvOrderCoupon;
    @BindView(R.id.rl_coupon_list)
    RelativeLayout rlCouponList;

    @BindView(R.id.iv_order_goldbean)
    ImageView ivOrderGoldbean;
    @BindView(R.id.cb_gold_must)
    CheckBox cbGoldMust;
    @BindView(R.id.rl_goldbean_pay)
    RelativeLayout rlGoldbeanPay;
    @BindView(R.id.iv_order_wechat)
    ImageView ivOrderWechat;
    @BindView(R.id.cb_wechat_must)
    CheckBox cbWechatMust;
    @BindView(R.id.rl_wechat_pay)
    RelativeLayout rlWechatPay;
    @BindView(R.id.iv_order_alipay)
    ImageView ivOrderAlipay;
    @BindView(R.id.cb_order_alipay)
    CheckBox cbOrderAlipay;
    @BindView(R.id.rl_alipay)
    RelativeLayout rlAlipay;
    @BindView(R.id.iv_order_union_pay)
    ImageView ivOrderUnionPay;
    @BindView(R.id.cb_order_union_pay)
    CheckBox cbOrderUnionPay;
    @BindView(R.id.rl_union_pay)
    RelativeLayout rlUnionPay;
    @BindView(R.id.ll_jindou_money)
    LinearLayout llJindouMoney;
    @BindView(R.id.scrollView)
    NestedScrollView scrollView;
    @BindView(R.id.tv_cart_sum)
    TextView tvCartSum;
    @BindView(R.id.tv_cart_freight)
    TextView tvCartFreight;
    @BindView(R.id.btn_cart_settleaccounts)
    Button btnCartSettleaccounts;
    @BindView(R.id.ll_order_pay)
    RelativeLayout llOrderPay;
    @BindView(R.id.ll_comfirm)
    LinearLayout llComfirm;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.iv_order_phone)
    ImageView ivOrderPhone;
    @BindView(R.id.ll_name_phone)
    LinearLayout llNamePhone;
    @BindView(R.id.ll_phone)
    LinearLayout llPhone;
    @BindView(R.id.ll_address)
    LinearLayout llAddress;
    @BindView(R.id.ll_cart_sum)
    LinearLayout llCartSum;
    @BindView(R.id.iv_order_clmember_pay)
    ImageView ivOrderClmemberPay;
    @BindView(R.id.tv_clmember_title)
    TextView tvClmemberTitle;
    @BindView(R.id.cb_order_clmember_pay)
    CheckBox cbOrderClmemberPay;
    @BindView(R.id.rl_clmember_pay)
    RelativeLayout rlClmemberPay;
    @BindView(R.id.tv_gold_money)
    TextView tvGoldMoney;
    @BindView(R.id.tv_golded_balance)
    TextView tvGoldedBalance;
    @BindView(R.id.tv_clmember_balance)
    TextView tvClmemberBalance;
    @BindView(R.id.iv_order_wechat2)
    ImageView ivOrderWechat2;
    @BindView(R.id.cb_wechat_must2)
    CheckBox cbWechatMust2;
    @BindView(R.id.rl_wechat_pay2)
    RelativeLayout rlWechatPay2;
    @BindView(R.id.ic_back)
    ImageView icBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rl_title)
    RelativeLayout rlTitle;
    @BindView(R.id.tv_order_youhui_money)
    TextView tvOrderYouhuiMoney;
    @BindView(R.id.ll_back)
    LinearLayout llBack;
    @BindView(R.id.rv_pay)
    RecyclerView rvPay;
    @BindView(R.id.tv_waimai)
    TextView tvWaimai;
    @BindView(R.id.tv_ziqu)
    TextView tvZiqu;
    @BindView(R.id.tv_tangshi)
    TextView tvTangshi;
    @BindView(R.id.tv_ziqu_way)
    TextView tvZiquWay;
    @BindView(R.id.tv_time_choose)
    TextView tvTimeChoose;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_distance)
    TextView tvDistance;
    @BindView(R.id.cb_agreement)
    CheckBox cbAgreement;
    @BindView(R.id.tv_agreemengt)
    TextView tvAgreemengt;
    @BindView(R.id.ll_ziqu)
    LinearLayout llZiqu;
    @BindView(R.id.tv_tableware_number)
    TextView tvTablewareNumber;
    @BindView(R.id.rl_tableware_number)
    RelativeLayout rlTablewareNumber;
    @BindView(R.id.fl_ziqu_waimai)
    FrameLayout flZiquWaimai;
    @BindView(R.id.tv_order_packagefree)
    TextView tvOrderPackagefree;
    @BindView(R.id.rl_order_packagefree)
    RelativeLayout rlOrderPackagefree;
    @BindView(R.id.tv_order_peisongfei)
    TextView tvOrderPeisongfei;
    @BindView(R.id.rl_order_peisongfei)
    RelativeLayout rlOrderPeisongfei;
    @BindView(R.id.rl_order_yunfei)
    RelativeLayout rlOrderYunfei;



    private ComfirmOrderAdapter comfirmOrderAdapter;
    private OrderPaytypeAdapter orderPaytypeAdapter;

    private ComfirmOrderBean.Data.OrderBatchShopVOList shopVOList;

    boolean isCheckAgreement;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_payment_order);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);

        StatusBarUtil.immersive(this);
        StatusBarUtil.setPaddingSmart(this, toolbar);
        tvTitle.setTextColor(getResources().getColor(R.color.transparent));
        initScroolview();
        orderType = getIntent().getStringExtra(ORDERTYPE);
        tenandId = getIntent().getStringExtra(TENANTID);
        shopsTypeId = getIntent().getIntExtra(SHOPSTYPEID, 0);

        LogUtils.d("模块分类shops=" + shopsTypeId + "店铺id=" + tenandId);
//        addressId = getIntent().getStringExtra(ADDRESSID);

        mobile = SPUtils.getString(Constant.USERNAME, "");


        orderGoodsDTOList = (OrderGoodsList) getIntent().getSerializableExtra(ORDERGOODSLIST);

        initView1();
        cbAgreement.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                isCheckAgreement = isChecked;
            }
        });

        if (shopsTypeId == Constant.typeIdRestaurant) {
            rlTablewareNumber.setVisibility(View.VISIBLE);
        }
    }


    private void initView1() {
        mPresenter = new ComfirmOrderPresenter();
        mPresenter.attachView(this);
        initAdapter();

        //初始化支付类型
        initPayAdapter();
        LogUtils.d("ttttttt=" + getToken());

        //外卖 到店去
//        repastWay = 1;


        //进来就去经纬度
        lat = SPUtils.getString(Constant.CURRENTLAT, "");
//        lat = "118.749185";
        lng = SPUtils.getString(Constant.CURRENTLON, "");
//        lng ="32.227922";
        LogUtils.d("lat= " + lat + "lng=" + lng);
        //先请求地址接口
        mPresenter.getAddressList(getToken());
        //请求支付的方式
        mPresenter.getenantIdPayMethod(getToken(), Constant.APPCLIENT, tenandId);

        if(shopsTypeId==2){
            //请求天数
            mPresenter.getPostDayList(shopsTypeId);
        }

        //优惠卷的接口
        mPresenter.getCouponList(getToken(), Utils.getRequestBodyArray(setCouponParam()), shopsTypeId);

    }

    List<ComfirmOrderBean.Data.OrderBatchShopVOList> comfirmList = new ArrayList<>();

    private void initAdapter() {

        comfirmOrderAdapter = new ComfirmOrderAdapter(this, R.layout.item_comfirm, comfirmList);
        rvCartItem.setLayoutManager(new LinearLayoutManager(this));
        rvCartItem.setAdapter(comfirmOrderAdapter);

        comfirmOrderAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int position) {
//                comfirmOrderAdapter.getData().get(position).getOrderGoodsDTOList();
            }
        });
    }

    List<TenantIdPayMethod.Data> payMethodList = new ArrayList<>();
    private int mPayposition;
    private String payTypeId;//支付方式id（查询店铺支付方式列表获得）

    private void initPayAdapter() {

        orderPaytypeAdapter = new OrderPaytypeAdapter(this, R.layout.item_pay_method, payMethodList);
        rvPay.setLayoutManager(new LinearLayoutManager(this));
        rvPay.setAdapter(orderPaytypeAdapter);

        orderPaytypeAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int position) {
                mPayposition = position;
                orderPaytypeAdapter.setThisPosition(position);

//                comfirmOrderAdapter.getData().get(position).getOrderGoodsDTOList();
            }
        });
    }

    private int mOffset = 0;
    private int mScrollY = 0;

    private void initScroolview() {


        scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            int lastScrollY = 0;
            int h = Global.dp2px(80);
            int color = ContextCompat.getColor(getApplicationContext(), R.color.white) & 0x00ffffff;

            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

                if (lastScrollY < h) {
                    scrollY = Math.min(h, scrollY);
                    mScrollY = scrollY > h ? h : scrollY;
//                    buttonBarLayout.setAlpha(1f * mScrollY / h);
                    toolbar.setBackgroundColor(((255 * mScrollY / h) << 24) | color);
                    ivHeader.setTranslationY(mOffset - mScrollY);
                }
                if (scrollY == 0) {
                    tvTitle.setTextColor(getResources().getColor(R.color.transparent));
//                    llBlindBgsearch.setBackground(getResources().getDrawable(R.drawable.store_left_boom_shape_30));
                    icBack.setBackgroundResource(R.drawable.ic_black_back);

                } else {
                    tvTitle.setTextColor(getResources().getColor(R.color.color_333333));
//                    llBlindBgsearch.setBackground(getResources().getDrawable(R.drawable.store_left_top_shape_30));
                    icBack.setBackgroundResource(R.drawable.ic_black_back);
                    tvTitle.setText("创建订单");

                }

                lastScrollY = scrollY;
            }
        });
        toolbar.setBackgroundColor(0);


    }

    //购物车跳转的  直接购买的判断
    OrderGoodsList orderGoodsDTOList;


    //优惠卷id
    private String couponUserId;
    private String addressId;
    private String mobile;
    private String orderType; //商超 餐饮 孕育等
    private String realName;
    private String remark;
    private String payType = "3";
    private String lat;
    private String lng;
    private String tenandId;
    private int shopsTypeId;

    //餐饮需要传递的参数
    private int bearingType;
    private String expectFinishTimeLimit;
    private String finishTimeTitle;
    private int freight;
    private int hasFreightTransport;
    private int isExpectFinishOrder;
    private String maxRange;
    private String mealTime;
    private int packageFee;
    //默认是到店自取为1
    private int repastWay = 1;
    private int seatId;
    private String seatNum;
    private int sellerPostType;
    private int startTransportFee;
    private int tablewareCount; //餐具数量

    //参数设置
    private JSONArray setRequestParam() {

        JSONArray array = new JSONArray();

        JSONObject jsonObject = new JSONObject();

        try {


            jsonObject.put("addrId", addressId);
            LogUtils.v("确认订单的地址id" + addressId);

            //使用优惠卷的id
            if (TextUtils.isEmpty(couponUserId)) {
                jsonObject.put("couponUserId", "");
            } else {
                jsonObject.put("couponUserId", couponUserId);
            }
            LogUtils.v("优惠卷id" + couponUserId);

            jsonObject.put("mobile", mobile);
            jsonObject.put("orderType", orderType);
            jsonObject.put("realName", "android");
            jsonObject.put("postType", "0");
            jsonObject.put("tenantId", tenandId);


            jsonObject.put("remark", remark);

            jsonObject.put("payType", payType);


            jsonObject.put("lat", "23.184225");
            jsonObject.put("lng", "113.236718");

            LogUtils.d("lat= " + lat + "lng=" + lng);
            if (orderGoodsDTOList != null) {
                // 1个数组参数
                LogUtils.d("预订单的购物车数量---" + orderGoodsDTOList.getOrderGoodsDTOList().size());
                JSONArray jsonArray = new JSONArray();

                for (int i = 0; i < orderGoodsDTOList.getOrderGoodsDTOList().size(); i++) {
                    JSONObject object = new JSONObject();
                    object.put("amount", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getAmount());
                    object.put("goodsId", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getGoodsId());
                    object.put("categoryIds", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getCategoryIds());
                    object.put("isSpec", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getIsSpec());
                    object.put("goodsSkuId", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getGoodsSkuId());
                    object.put("price", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getPrice());
                    object.put("discountPrice", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getDiscountPrice());
                    jsonArray.put(object);
                }

                jsonObject.put("orderGoodsDTOList", jsonArray);

            }

            //判断是否餐饮 便利店类型的
            if (shopsTypeId == Constant.typeIdRestaurant || shopsTypeId == Constant.typeIdMinimart || shopsTypeId == Constant.typeIdPharmaceuticals
                    || shopsTypeId == Constant.typeIdBreed) {
                JSONObject orderRestaurant = new JSONObject();
                orderRestaurant.put("bearingType", bearingType);
                orderRestaurant.put("expectFinishTimeLimit", expectFinishTimeLimit);
                orderRestaurant.put("finishTimeTitle", finishTimeTitle);
                orderRestaurant.put("freight", freight);
                orderRestaurant.put("hasFreightTransport", "0");
                orderRestaurant.put("isExpectFinishOrder", "0");
                orderRestaurant.put("maxRange", "0");
                orderRestaurant.put("mealTime", mealTime);
                orderRestaurant.put("packageFee", "0");
//            0-到店堂食 1-到店自取 2-外卖配送
                orderRestaurant.put("repastWay", repastWay);
                orderRestaurant.put("seatNum", "0");
                orderRestaurant.put("sellerPostType", "0");
                orderRestaurant.put("tablewareCount", tablewareCount);

                jsonObject.put("orderRestaurantExDTO", orderRestaurant);
            }


            array.put(jsonObject);

        } catch (JSONException e) {
            e.printStackTrace();
            LogUtils.d("预订单的异常" + e.getMessage());
        }
        return array;
    }


    /*优惠卷的参数传递*/
    private JSONArray setCouponParam() {

        JSONArray jsonArray = new JSONArray();
        try {

            if (orderGoodsDTOList != null) {
                // 1个数组参数
                JSONObject object = new JSONObject();
                for (int i = 0; i < orderGoodsDTOList.getOrderGoodsDTOList().size(); i++) {
                    object.put("amount", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getAmount());
                    object.put("goodsId", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getGoodsId());
                    object.put("categoryIds", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getCategoryIds());
                    object.put("isSpec", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getIsSpec());
                    object.put("goodsSkuId", orderGoodsDTOList.getOrderGoodsDTOList().get(i).getGoodsSkuId());

                }
                jsonArray.put(object);

            }

        } catch (JSONException e) {
            e.printStackTrace();
            LogUtils.d("优惠卷参数的异常" + e.getMessage());
        }
        return jsonArray;
    }


    @Override
    public void onEmpty(Object tag) {
        super.onEmpty(tag);
        ToastUtils.show(tag);
//        finish();
    }

    @Override
    public void getComfirmOrder(ComfirmOrderBean bean) {


        if (bean != null) {

            shopVOList = bean.getData().getOrderBatchShopVOList().get(0);

            //判断餐饮等 才要显示外卖 到店自取
            if (shopsTypeId == Constant.typeIdRestaurant || shopsTypeId == Constant.typeIdMinimart
                    || shopsTypeId == Constant.typeIdPharmaceuticals || shopsTypeId == Constant.typeIdBreed) {

                rlOrderYunfei.setVisibility(View.GONE);//运费
                rlOrderPeisongfei.setVisibility(View.VISIBLE);//配送费
                rlOrderPackagefree.setVisibility(View.VISIBLE); //包装费

                tvOrderPeisongfei.setText(Utils.formatZeroNumber(shopVOList.getOrderRestaurantExDTO().getFreight()));

                tvOrderPackagefree.setText(Utils.formatZeroNumber(shopVOList.getOrderRestaurantExDTO().getPackageFee()));

                llZiqu.setVisibility(View.VISIBLE); //自取的总布局
                flZiquWaimai.setVisibility(View.VISIBLE); //外卖 自取 堂食的显示
                LogUtils.d("repastway=" + repastWay);
                switch (repastWay) {
                    case 0:
                        tvZiquWay.setText("就餐时间");
                        tvAgreemengt.setText(getResources().getString(R.string.eating_in_store_agreement));
                        setRestantType(tvTangshi, tvWaimai, tvZiqu);
                        rlOrderAddress.setVisibility(View.GONE);
                        llZiqu.setVisibility(View.VISIBLE);
                        break;
                    case 1:
                        tvZiquWay.setText("自取时间");
                        tvAgreemengt.setText(getResources().getString(R.string.to_store_service_agreement));
                        rlOrderAddress.setVisibility(View.GONE);
                        setRestantType(tvZiqu, tvWaimai, tvTangshi);
                        llZiqu.setVisibility(View.VISIBLE);
                        break;
                    case 2:
                        setRestantType(tvWaimai, tvZiqu, tvTangshi);
                        rlOrderAddress.setVisibility(View.VISIBLE);
                        llZiqu.setVisibility(View.GONE);
                        break;
                }
                //根据dadaBind判断不同外卖是否显示
                if (bean.getData().getDadaBind()) {
                    tvWaimai.setVisibility(View.VISIBLE);

                } else {
                    tvWaimai.setVisibility(View.GONE);
                }
            } else {
                rlOrderYunfei.setVisibility(View.VISIBLE);//运费
                rlOrderPeisongfei.setVisibility(View.GONE);//配送费
                rlOrderPackagefree.setVisibility(View.GONE); //包装费

                llZiqu.setVisibility(View.GONE); //自取总布局
                flZiquWaimai.setVisibility(View.GONE); //外卖 自取 堂食的显示

                rlOrderAddress.setVisibility(View.VISIBLE);
                //商超地址选择
                if (shopVOList.getAddress().isEmpty()) {

                    tvNoAddress.setVisibility(View.VISIBLE);
                    tvCheckAddress.setVisibility(View.VISIBLE);
                    llNamePhone.setVisibility(View.GONE);

                    tvOrderName.setVisibility(View.GONE);
                    tvOrderPhone.setVisibility(View.GONE);
                    tvOrderAddress.setVisibility(View.GONE);

                } else {
                    Address userAddress = new Gson().fromJson(shopVOList.getAddress(), Address.class);
                    tvNoAddress.setVisibility(View.GONE);
                    tvCheckAddress.setVisibility(View.GONE);
                    llNamePhone.setVisibility(View.VISIBLE);
                    tvOrderName.setVisibility(View.VISIBLE);
                    tvOrderPhone.setVisibility(View.VISIBLE);
                    tvOrderAddress.setVisibility(View.VISIBLE);
                    tvOrderName.setText(userAddress.getConsignee());
                    tvOrderPhone.setText(Utils.getStarMobile(userAddress.getMobile()));
                    tvOrderAddress.setText(userAddress.getProvince() + " " + userAddress.getCity() + " " + userAddress.getDistrict() + " "
                            + userAddress.getAddress());
                    LogUtils.d("进来~~~");
                }
            }

            if (tablewareCount == 0) {
                tvTablewareNumber.setText("不需要餐具,请选择");
            } else {
                tvTablewareNumber.setText(tablewareCount + "份餐具,请选择");
            }


            //adapter
            for (int i = 0; i < bean.getData().getOrderBatchShopVOList().size(); i++) {
                comfirmList.add(bean.getData().getOrderBatchShopVOList().get(i));
            }
            comfirmOrderAdapter.notifyDataSetChanged();

            //电话号码
            tvPhone.setText(mobile);
            //距离您
            tvDistance.setText(shopVOList.getDistance() + "km");
//            BigDecimalUtil.sub()
            tvOrderPrice.setText(Utils.doubleTrans2(shopVOList.getGoodsTotal())); //订单价格
            tvOrderYunfei.setText(Utils.doubleTrans2(shopVOList.getFreightPrice()) + ""); //订单运费
            tvOrderCartSum.setText(Utils.doubleTrans2(bean.getData().getTotalActuallyPaid()) + "");

            if (couponListBean.getData().size() > 0) {
                rlCouponList.setVisibility(View.VISIBLE);
                tvOrderCoupon.setText("¥" + Utils.doubleTrans2(shopVOList.getDiscountTotalAmount()));
            } else {
                tvOrderCoupon.setText("无优惠券");
                rlCouponList.setVisibility(View.GONE);
            }


            tvOrderYouhuiMoney.setText(Utils.doubleTrans2(shopVOList.getDiscountTotalAmount()));

            //实际支付金额
            tvCartSum.setText("合计：¥" + Utils.doubleTrans2(bean.getData().getTotalAmount()) + "");

        }
    }

    CouponListBean couponListBean;

    @Override
    public void getCouponList(CouponListBean bean) {

        couponListBean = bean;
        if (couponListBean.getData().size() > 0) {
            couponUserId = couponListBean.getData().get(0).getId();
            couponListBean.getData().get(0).setUseStatus(1);
        }
        mPresenter.getComfirmOrder(getToken(), Utils.getRequestBodyArray(setRequestParam()), shopsTypeId);
    }


    @Override
    public void getPayTypeConfig(PayTypeConfig bean) {

    }


    @Override
    public void getenantIdPayMethod(TenantIdPayMethod bean) {

        for (int i = 0; i < bean.getData().size(); i++) {
            payMethodList.add(bean.getData().get(i));

        }
        orderPaytypeAdapter.notifyDataSetChanged();


    }

    // 支付方式id（查询店铺支付方式列表获得）
    private String orderNo;
    private String payMoney;
    private Double redbean;

    //生成订单接口
    @Override
    public void getGenerateOrder(ComfirmOrderBean bean) {

        if (bean.getCode() == Constant.HTTPCODE200) {
            payMoney = String.valueOf(bean.getData().getTotalActuallyPaid());
            //获取订单号 去支付
            orderNo = bean.getData().getOrderBatchShopVOList().get(0).getOrderNo();
            //赠送的红豆
            redbean = bean.getData().getTotalGiveBeans();
            //封装支付传参
            JSONObject jsonObject = PayUtils.setPayParam(orderNo, orderPaytypeAdapter.getData().get(mPayposition).getPayType(), orderPaytypeAdapter.getData().get(mPayposition).getId());
            mPresenter.getPayOrder(getToken(), Utils.getRequestBody(jsonObject));
        }


    }

    //支付成功的回调
    @Override
    public void getPayOrder(PayOrderBean bean) {
        switch (bean.getCode()) {
            case Constant.HTTPCODE200:
                isPaySuccess = true;
                payIntentActivity("");
                break;
            case Constant.HTTPCODE400:
            case Constant.HTTPCODE401:
            case Constant.HTTPCODE404:
            case Constant.HTTPCODE500:
                isPaySuccess = false;
                payIntentActivity(bean.getMsg());
                break;
            case Constant.HTTPCODE409:
                isPaySuccess = false;
                payIntentActivity(bean.getMsg());
                break;
            case Constant.HTTPCODE410:
                isPaySuccess = false;
                payIntentActivity(bean.getMsg());
                break;
        }

    }

    //
    @Override
    public void getAddressList(AddressListBean bean) {

        for (int i = 0; i < bean.getData().size(); i++) {
            if (bean.getData().get(i).getIsDefault() == 1) {
                addressId = bean.getData().get(i).getId();
            }
        }


    }

    //时间的请求
    int dayType = 1;

    List<PostDayBean.Data> dayList = new ArrayList<>();

    private DayListAdapter dayListAdapter;
    private DayTimeListAdapter timeListAdapter;
    int dayPosition;

    int timePosition;

    private String timeName;

    private PostDayBean postDaybean;

    private PostTimeListBean postTimeDaybean;

    @Override
    public void getPostDayList(PostDayBean bean) {
        //默认选中今天
        postDaybean = bean;

        mPresenter.getPostTimeList(dayType, shopsTypeId);
        for (int i = 0; i < bean.getData().size(); i++) {
            dayList.add(bean.getData().get(i));
        }

    }

    List<PostTimeListBean.Data> timeDayList = new ArrayList<>();

    //只设置一次
    boolean isTimeFisrt = true;

    @Override
    public void getPostTimeList(PostTimeListBean bean) {
        postTimeDaybean = bean;
        for (int i = 0; i < bean.getData().size(); i++) {
            timeDayList.add(bean.getData().get(i));
        }
        if (timeListAdapter != null) {
            timeListAdapter.setThisPosition(timePosition);
            timeListAdapter.notifyDataSetChanged();
        }
        if (repastWay == 1) {
            bean.getData().get(0).setTimeHouseAndMinute("立即自取");
        } else if (repastWay == 0) {
            bean.getData().get(0).setTimeHouseAndMinute("立即就餐");
        }
        if (isTimeFisrt) {
            timeName = postDaybean.getData().get(0).getDayTitle() + bean.getData().get(0).getTimeHouseAndMinute();
            tvTimeChoose.setText(timeName);

            finishTimeTitle = timeName; //	预计送达时间说明
            mealTime = timeName;
            expectFinishTimeLimit = bean.getData().get(0).getSeconds() + "000"; //预约送达时间
            isTimeFisrt = false;
        }


    }

    //是否支付成功
    private boolean isPaySuccess = true;

    //跳转到订单详情和支付界面
    private void payIntentActivity(String msg) {
        Intent intent = new Intent(mContext, PayStatusActivity.class);
        intent.putExtra(PayStatusActivity.ORDERNO, orderNo);
        intent.putExtra(PayStatusActivity.PAYTYPE, payType);
        intent.putExtra(PayStatusActivity.PAYMONEY, payMoney);
        intent.putExtra(PayStatusActivity.PAYSUCCESS, isPaySuccess);
        intent.putExtra(PayStatusActivity.PAYMSG, msg);
//        intent.putExtra(PayStatusActivity.SHOPSTYPEID, );
        intent.putExtra(PayStatusActivity.TENANTID, tenandId);
        intent.putExtra(PayStatusActivity.REDBEAN, redbean);
        LogUtils.d("getpaymsg信息**" + msg);
        startActivity(intent);
        finish();
    }

    boolean isAddress = true;

    @OnClick({R.id.rl_order_address, R.id.tv_order_remarks_edit, R.id.btn_cart_settleaccounts, R.id.rl_coupon_list
            , R.id.ll_back, R.id.tv_waimai, R.id.tv_ziqu, R.id.tv_tangshi, R.id.tv_phone, R.id.tv_time_choose, R.id.rl_tableware_number})
    public void onViewClicked(View view) {

        switch (view.getId()) {
            case R.id.rl_order_address:
                //跳转地址管理界面
                startActivityForResult(new Intent(mContext, AddressManagerActivity.class)
                        .putExtra(ADDRESSID, isAddress), REQUEST_CODE_ADDRESS);

                break;
            case R.id.tv_order_remarks_edit:
                //弹出编辑对话框界面
                startActivityForResult(new Intent(mContext, OrderEditActivity.class)
                        , REQUEST_CODE_EDIT);

                break;
            //餐具
            case R.id.rl_tableware_number:
                showTableWalreDialog();
                break;
            case R.id.rl_coupon_list:
                if (couponListBean.getData().size() > 0) {
                    showCouponDialog(couponListBean);
                }
                break;
            case R.id.btn_cart_settleaccounts:

                if (shopsTypeId == Constant.typeIdRestaurant || shopsTypeId == Constant.typeIdMinimart || shopsTypeId == Constant.typeIdPharmaceuticals
                        || shopsTypeId == Constant.typeIdBreed) {
                    if (repastWay == 1) {
                        if (!isCheckAgreement) {
                            ToastUtils.show("请同意" + getResources().getString(R.string.to_store_service_agreement));
                            return;
                        }
                    } else if (repastWay == 0) {
                        if (!isCheckAgreement) {
                            ToastUtils.show("请同意" + getResources().getString(R.string.eating_in_store_agreement));
                            return;
                        }
                    }
                } else {
                    if (shopVOList.getAddress().isEmpty()) {
                        ToastUtils.show(getResources().getString(R.string.check_address));
                        return;
                    }
                }

                //选择支付方式
                BaseDialog.showDialog(mContext, "确定使用" + orderPaytypeAdapter.getData().get(mPayposition).getDescriptions() + "支付吗", "取消", "确定", new OnConfirmListener() {
                    @Override
                    public void onConfirm() {

                        payType = orderPaytypeAdapter.getData().get(mPayposition).getPayType();

                        mPresenter.getGenerateOrder(getToken(), Utils.getRequestBodyArray(setRequestParam()), shopsTypeId);
                    }
                }, false);

                break;
            case R.id.ll_back:
                finish();
                break;
            case R.id.tv_waimai:

                repastWay = 2;
                setRestantType(tvWaimai, tvZiqu, tvTangshi);
                cbAgreement.setChecked(false);
                comfirmList.clear();
                mPresenter.getComfirmOrder(getToken(), Utils.getRequestBodyArray(setRequestParam()), shopsTypeId);
                break;
            case R.id.tv_ziqu:
                repastWay = 1;
                if (postTimeDaybean != null) {
                    postTimeDaybean.getData().get(0).setTimeHouseAndMinute("立即自取");
                    timePosition = 0;
                    timeName = postDaybean.getData().get(dayPosition).getDayTitle() + postTimeDaybean.getData().get(0).getTimeHouseAndMinute();
//                    finishTimeTitle = timeName;
//                    mealTime = timeName;
//                    expectFinishTimeLimit =
                    tvTimeChoose.setText(timeName);
                }
                setRestantType(tvZiqu, tvWaimai, tvTangshi);
                cbAgreement.setChecked(false);
                comfirmList.clear();
                mPresenter.getComfirmOrder(getToken(), Utils.getRequestBodyArray(setRequestParam()), shopsTypeId);
                break;
            case R.id.tv_tangshi:
                repastWay = 0;
                if (postTimeDaybean != null) {
                    timePosition = 0;
                    postTimeDaybean.getData().get(0).setTimeHouseAndMinute("立即就餐");
                    timeName = postDaybean.getData().get(dayPosition).getDayTitle() + postTimeDaybean.getData().get(0).getTimeHouseAndMinute();
                    tvTimeChoose.setText(timeName);
                }
                setRestantType(tvTangshi, tvWaimai, tvZiqu);
                cbAgreement.setChecked(false);
                comfirmList.clear();
                mPresenter.getComfirmOrder(getToken(), Utils.getRequestBodyArray(setRequestParam()), shopsTypeId);
                break;
            case R.id.tv_phone:
                //弹出编辑对话框
                new XPopup.Builder(this).asInputConfirm("电话号码", "", tvPhone.getText().toString(), "请输入电话号码",
                        new OnInputConfirmListener() {
                            @Override
                            public void onConfirm(String text) {
                                if (!Utils.isMobileNO(text)) {
                                    ToastUtils.show("请输入正确手机号码");
                                    return;
                                }
                                if (!text.isEmpty() && !text.equals(tvPhone.getText().toString())) {
                                    tvPhone.setText(text);
                                    mobile = text;
                                }
                            }
                        })
                        .show();
                break;
            case R.id.tv_time_choose:
                //弹出对话框
                showTimeDialog(postDaybean, postTimeDaybean);
                break;
        }
    }

    //设置外卖 到店自取状态
    private void setRestantType(TextView tv1, TextView tv2, TextView tv3) {
        tv1.setBackground(getResources().getDrawable(R.drawable.corners_waimai_common_default));
        tv1.setTextColor(getResources().getColor(R.color.white));
        tv2.setTextColor(getResources().getColor(R.color.all_black_text));
        tv2.setBackground(getResources().getDrawable(R.drawable.corner_waimai_30));
        tv3.setTextColor(getResources().getColor(R.color.all_black_text));
        tv3.setBackground(getResources().getDrawable(R.drawable.corner_waimai_30));
    }


    private static final int REQUEST_CODE_ADDRESS = 1001;
    private static final int REQUEST_CODE_EDIT = 1002;


    //返回选中城市
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_ADDRESS && resultCode == Activity.RESULT_OK) {
            if (data != null) {
                addressId = data.getStringExtra("ADDRESS_DATA");
                comfirmList.clear();
                mPresenter.getComfirmOrder(getToken(), Utils.getRequestBodyArray(setRequestParam()), shopsTypeId);
            }

        } else if (requestCode == REQUEST_CODE_EDIT && resultCode == Activity.RESULT_OK) {
            if (data != null) {
                remark = data.getStringExtra(OrderEditActivity.EDITCONTENT);
                tvOrderRemarksEdit.setText(remark);
                comfirmList.clear();
                mPresenter.getComfirmOrder(getToken(), Utils.getRequestBodyArray(setRequestParam()), shopsTypeId);
            }

        }
    }


    //餐具对话框
    private void showTableWalreDialog() {

        BottomPopup bottomPopup = new BottomPopup(this);

        new XPopup.Builder(this)
//                .moveUpToKeyboard(false)
                .dismissOnTouchOutside(true)
                .borderRadius(10)
                .animationDuration(150)
                .asCustom(bottomPopup)
                .show();

    }


    /*编辑备注*/
    class BottomPopup extends BottomPopupView {


        //注意：自定义弹窗本质是一个自定义View，但是只需重写一个参数的构造，其他的不要重写，所有的自定义弹窗都是这样。
        public BottomPopup(@NonNull Context context) {
            super(context);
        }

        // 返回自定义弹窗的布局
        @Override
        protected int getImplLayoutId() {
            return R.layout.dialog_order_tablenumber;
        }

        // 执行初始化操作，比如：findView，设置点击，或者任何你弹窗内的业务逻辑
        @Override
        protected void onCreate() {
            super.onCreate();

            Button btnComfirm = findViewById(R.id.btn_comfirm);
            ImageView imageView = findViewById(R.id.iv_dialog_delete);

            ImageView ivTableMinus = findViewById(R.id.iv_table_minus);
            ImageView ivTableAdd = findViewById(R.id.iv_table_add);

            LinearLayout llNeddTable = findViewById(R.id.ll_nedd_table);

            LinearLayout llNoNeedTable = findViewById(R.id.ll_no_need_table);

            LinearLayout lltable = findViewById(R.id.ll_table);

            TextView tvTableNum = findViewById(R.id.tv_table_num);

            llNeddTable.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    llNeddTable.setBackground(mContext.getResources().getDrawable(R.drawable.table_bg_shape_pressed));
                    llNoNeedTable.setBackground(mContext.getResources().getDrawable(R.drawable.table_bg_shape_default));
                    tvTableNum.setText("1");
                    lltable.setVisibility(VISIBLE);

                }
            });

            llNoNeedTable.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    tvTableNum.setText("0");
                    llNeddTable.setBackground(mContext.getResources().getDrawable(R.drawable.table_bg_shape_default));
                    llNoNeedTable.setBackground(mContext.getResources().getDrawable(R.drawable.table_bg_shape_pressed));
                    lltable.setVisibility(GONE);
                }
            });


            //餐具加减
            ivTableMinus.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (tvTableNum.getText().toString().equals("1")) {
                        ToastUtils.show("最少一份餐具");
                        return;
                    }
                    String sub = BigDecimalUtil.sub(tvTableNum.getText().toString(), "1");
                    tvTableNum.setText(sub);
                }
            });

            ivTableAdd.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (tvTableNum.getText().toString().equals("10")) {
                        ToastUtils.show("最多10份餐具");
                        return;
                    }
                    String add = BigDecimalUtil.add(tvTableNum.getText().toString(), "1");
                    tvTableNum.setText(add);
                }
            });

            imageView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    dismiss(); // 关闭弹窗
                }
            });


            btnComfirm.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    dismiss();
                    comfirmList.clear();
                    tablewareCount = Integer.parseInt(tvTableNum.getText().toString());

                    JSONArray jsonObject = setRequestParam();
                    mPresenter.getComfirmOrder(getToken(), Utils.getRequestBodyArray(jsonObject), shopsTypeId);

                }
            });
        }

        // 设置最大宽度，看需要而定，
        @Override
        protected int getMaxWidth() {
            return super.getMaxWidth();
        }

        // 设置最大高度，看需要而定
        @Override
        protected int getMaxHeight() {
            return super.getMaxHeight();
        }

        // 设置自定义动画器，看需要而定
        @Override
        protected PopupAnimator getPopupAnimator() {
            return super.getPopupAnimator();
        }

        /**
         * 弹窗的宽度，用来动态设定当前弹窗的宽度，受getMaxWidth()限制
         *
         * @return
         */
        protected int getPopupWidth() {
            return 0;
        }

        /**
         * 弹窗的高度，用来动态设定当前弹窗的高度，受getMaxHeight()限制
         *
         * @return
         */
        protected int getPopupHeight() {
            return 0;
        }


    }

    //*******************start *****************************//

    //显示优惠卷对话框
    private void showCouponDialog(CouponListBean couponListBean) {

        CouponBottomPopup couponBottomPopup = new CouponBottomPopup(this);
        couponBottomPopup.setCouponsLists(couponListBean.getData());
        new XPopup.Builder(this)
//                .moveUpToKeyboard(false)
                .borderRadius(8)
                .dismissOnTouchOutside(true)
                .enableDrag(false)
                .animationDuration(150)
                .asCustom(couponBottomPopup)
                .show();
    }

    /*优惠卷选择*/
    class CouponBottomPopup extends BottomPopupView {


        //注意：自定义弹窗本质是一个自定义View，但是只需重写一个参数的构造，其他的不要重写，所有的自定义弹窗都是这样。
        public CouponBottomPopup(@NonNull Context context) {
            super(context);
        }

        // 返回自定义弹窗的布局
        @Override
        protected int getImplLayoutId() {
            return R.layout.dialog_coupon_list;
        }

        // 执行初始化操作，比如：findView，设置点击，或者任何你弹窗内的业务逻辑
        @Override
        protected void onCreate() {
            super.onCreate();
            Button btncomfirm = findViewById(R.id.btn_dialog_comfirm);
            ImageView imageView = findViewById(R.id.iv_dialog_delete);
            RecyclerView rvCoupon = findViewById(R.id.rv_dialog_coupon);
            OrderCouponAdapter couponAdapter = new OrderCouponAdapter(mContext, R.layout.item_order_coupon_list, couponsLists);
            rvCoupon.setLayoutManager(new LinearLayoutManager(mContext));
            rvCoupon.setAdapter(couponAdapter);
            couponAdapter.notifyDataSetChanged();


            couponAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {


                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {


                    for (int i = 0; i < couponsLists.size(); i++) {
                        couponsLists.get(i).setUseStatus(0); //全部设置未选中
                    }
                    couponUserId = couponAdapter.getData().get(position).getId();
                    couponAdapter.getData().get(position).setUseStatus(1);
                    couponAdapter.setThisPosition(position);
                    couponAdapter.notifyDataSetChanged();
                    dismiss();
                    comfirmList.clear();
                    mPresenter.getComfirmOrder(getToken(), Utils.getRequestBodyArray(setRequestParam()), shopsTypeId);


                }
            });

            for (int i = 0; i < couponsLists.size(); i++) {
                couponsLists.get(i).setTagSelect(false);
            }
            //显示和隐藏
            couponAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    couponAdapter.setThisTagPosition(position);

                    switch (view.getId()) {
                        case R.id.rl_isshow:
                            if (!couponAdapter.getData().get(position).isTagSelect()) {
                                couponAdapter.getData().get(position).setTagSelect(true);

                            } else {
                                couponAdapter.getData().get(position).setTagSelect(false);
                            }
                            break;
                    }
                    couponAdapter.notifyItemChanged(position);
                }
            });

            btncomfirm.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    for (int i = 0; i < couponsLists.size(); i++) {
                        couponsLists.get(i).setUseStatus(0); //全部设置未选中
                    }
                    dismiss();
                    couponUserId = "";
                    comfirmList.clear();
                    mPresenter.getComfirmOrder(getToken(), Utils.getRequestBodyArray(setRequestParam()), shopsTypeId);

                }
            });


            imageView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });

        }

        // 设置最大宽度，看需要而定，
        @Override
        protected int getMaxWidth() {
            return super.getMaxWidth();
        }

        // 设置最大高度，看需要而定
        @Override
        protected int getMaxHeight() {
            return super.getMaxHeight();
        }

        // 设置自定义动画器，看需要而定
        @Override
        protected PopupAnimator getPopupAnimator() {
            return super.getPopupAnimator();
        }

        protected int getPopupWidth() {
            return 0;
        }

        protected int getPopupHeight() {
            return 0;
        }

        List<CouponListBean.Data> couponsLists;

        public List<CouponListBean.Data> getCouponsLists() {
            return couponsLists;
        }

        public void setCouponsLists(List<CouponListBean.Data> couponsLists) {
            this.couponsLists = couponsLists;
        }

    }


    //*******************end *****************************//

    //*******************时间选择器start *****************************//

    //显示优惠卷对话框
    private void showTimeDialog(PostDayBean postDayBean, PostTimeListBean postTimeDaybean) {

        TimeChoosePopup timeChoosePopup = new TimeChoosePopup(this);
        timeChoosePopup.setDayList(postDayBean.getData());
//        timeChoosePopup.setDayTimeList(postTimeDaybean.getData());
        new XPopup.Builder(this)
//                .moveUpToKeyboard(false)
                .borderRadius(8)
                .dismissOnTouchOutside(true)
                .enableDrag(false)
                .animationDuration(150)
                .asCustom(timeChoosePopup)
                .show();
    }

    /*时间选择选择*/
    class TimeChoosePopup extends BottomPopupView {


        //注意：自定义弹窗本质是一个自定义View，但是只需重写一个参数的构造，其他的不要重写，所有的自定义弹窗都是这样。
        public TimeChoosePopup(@NonNull Context context) {
            super(context);
        }

        // 返回自定义弹窗的布局
        @Override
        protected int getImplLayoutId() {
            return R.layout.dialog_time_choose;
        }

        // 执行初始化操作，比如：findView，设置点击，或者任何你弹窗内的业务逻辑
        @Override
        protected void onCreate() {
            super.onCreate();

            RecyclerView rvDay = findViewById(R.id.rv_day);
            RecyclerView rvTimeChoose = findViewById(R.id.rv_time_choose);
            ImageView ivDialogDelete = findViewById(R.id.iv_dialog_delete);

            rvDay.setLayoutManager(new LinearLayoutManager(mContext));
            dayListAdapter = new DayListAdapter(mContext, dayList);
            rvDay.setAdapter(dayListAdapter);
            dayListAdapter.notifyDataSetChanged();

            dayListAdapter.setThisPosition(dayPosition);

            dayListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    //请求刷新数据
                    dayPosition = position;
                    //切换的时候 更换位置
                    timePosition = 0;

                    LogUtils.d("time的位置=" + timePosition);
                    timeDayList.clear();
                    dayListAdapter.setThisPosition(position);
                    mPresenter.getPostTimeList(dayListAdapter.getData().get(position).getType(), shopsTypeId);
                }
            });


            rvTimeChoose.setLayoutManager(new LinearLayoutManager(mContext));
            timeListAdapter = new DayTimeListAdapter(mContext, timeDayList);
            rvTimeChoose.setAdapter(timeListAdapter);
            timeListAdapter.notifyDataSetChanged();

            timeListAdapter.setThisPosition(timePosition);
            timeListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    timePosition = position;
                    timeListAdapter.setThisPosition(position);
                    timeName = postDaybean.getData().get(dayPosition).getDayTitle() + postTimeDaybean.getData().get(position).getTimeHouseAndMinute();

                    finishTimeTitle = timeName; //	预计送达时间说明
                    mealTime = timeName;
                    expectFinishTimeLimit = postTimeDaybean.getData().get(position).getSeconds() + "000"; //预约送达时间 后台要求添加000
                    tvTimeChoose.setText(timeName);
                    dismiss();
                }
            });
            ivDialogDelete.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });


        }

        // 设置最大宽度，看需要而定，
        @Override
        protected int getMaxWidth() {
            return super.getMaxWidth();
        }

        // 设置最大高度，看需要而定
        @Override
        protected int getMaxHeight() {
            return super.getMaxHeight();
        }

        // 设置自定义动画器，看需要而定
        @Override
        protected PopupAnimator getPopupAnimator() {
            return super.getPopupAnimator();
        }

        protected int getPopupWidth() {
            return 0;
        }

        protected int getPopupHeight() {
            return 0;
        }

        private List<PostDayBean.Data> dayList;

//        private List<PostTimeListBean.Data> dayTimeList;

        public List<PostDayBean.Data> getDayList() {
            return dayList;
        }

        public void setDayList(List<PostDayBean.Data> dayList) {
            this.dayList = dayList;
        }

//        public List<PostTimeListBean.Data> getDayTimeList() {
//            return dayTimeList;
//        }
//
//        public void setDayTimeList(List<PostTimeListBean.Data> dayTimeList) {
//            this.dayTimeList = dayTimeList;
//        }
    }

    //*******************时间选择器end *****************************//

}
